/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package chatGUI;
import Controller.*;
import Model.ChatModel;
import java.awt.Color;
import java.awt.Event;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ButtonGroup;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

       

/**
 *
 * @author Ridiss
 */
public class ChatGui extends javax.swing.JFrame {
    private ChatController cont;
    private ChatModel userList;
    private JFileChooser fc;

    /**
     * Creates new form ChatGui
     */
    public ChatGui() {
        createJMenuBar();
        initComponents();
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        Recption.setEditable(false);
        fc = new JFileChooser();
        conxFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
        conxFrame.pack();
        conxFrame.setVisible(true);  
        
    }
    
    /**
     * Cette méthode permet d'instancier le gui
     * @param cont
     */
    public void setController(ChatController cont) {
            this.cont = cont;
        }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        conxFrame = new javax.swing.JFrame();
        jButton1 = new javax.swing.JButton();
        log = new javax.swing.JLabel();
        conxxlog = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        UserLab = new javax.swing.JLabel();
        deconnexion = new javax.swing.JButton();
        loginLabel = new javax.swing.JLabel();
        Bradio = new javax.swing.JRadioButton();
        jLabel3 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listUser = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        Recption = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        txtenvoi = new javax.swing.JTextArea();
        txtPan = new javax.swing.JPanel();
        BFile = new javax.swing.JButton();
        yesBt = new javax.swing.JButton();
        NoBt = new javax.swing.JButton();
        prgbar = new javax.swing.JProgressBar();
        pourcent = new javax.swing.JLabel();

        jButton1.setText("Connexion");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        log.setText("Nom d'utilisateur:");

        conxxlog.setText("login");
        conxxlog.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                conxxlogActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Lucida Calligraphy", 3, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 153, 255));
        jLabel1.setText("  Chat-Evolution L-I");

        jLabel2.setText("version 2.0");

        javax.swing.GroupLayout conxFrameLayout = new javax.swing.GroupLayout(conxFrame.getContentPane());
        conxFrame.getContentPane().setLayout(conxFrameLayout);
        conxFrameLayout.setHorizontalGroup(
            conxFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(conxFrameLayout.createSequentialGroup()
                .addGap(58, 58, 58)
                .addComponent(log)
                .addGroup(conxFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(conxFrameLayout.createSequentialGroup()
                        .addGap(45, 45, 45)
                        .addComponent(jLabel2))
                    .addGroup(conxFrameLayout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addGroup(conxFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton1)
                            .addComponent(conxxlog, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(212, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, conxFrameLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 411, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        conxFrameLayout.setVerticalGroup(
            conxFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, conxFrameLayout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addGroup(conxFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(conxxlog, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(log))
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addContainerGap(58, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("  Chat-Evolution L-I 2.0");
        setBackground(new java.awt.Color(58, 107, 139));
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(58, 107, 139));

        UserLab.setFont(new java.awt.Font("Lucida Calligraphy", 1, 18)); // NOI18N
        UserLab.setText("    Bienvenue:");

        deconnexion.setText("Déconnexion");
        deconnexion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deconnexionActionPerformed(evt);
            }
        });

        loginLabel.setFont(new java.awt.Font("Lucida Calligraphy", 1, 18)); // NOI18N
        loginLabel.setForeground(new java.awt.Color(102, 255, 51));
        loginLabel.setToolTipText("");

        Bradio.setBackground(new java.awt.Color(51, 255, 51));
        Bradio.setEnabled(false);
        Bradio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BradioActionPerformed(evt);
            }
        });

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/chatGUI/images-2.jpeg"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(UserLab, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 204, Short.MAX_VALUE)
                .addComponent(loginLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addGap(135, 135, 135)
                .addComponent(Bradio)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(deconnexion, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(49, 49, 49))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(Bradio)
                        .addComponent(deconnexion))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(loginLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3)
                            .addComponent(UserLab))
                        .addGap(6, 6, 6)))
                .addGap(6, 6, 6))
        );

        UserLab.getAccessibleContext().setAccessibleName("utilisateur");

        jPanel2.setBackground(new java.awt.Color(58, 107, 139));

        listUser.setBackground(new java.awt.Color(247, 247, 250));
        listUser.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Liste d'utilisateurs", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Lucida Calligraphy", 1, 12))); // NOI18N
        listUser.setFont(new java.awt.Font("Lucida Calligraphy", 1, 12)); // NOI18N
        listUser.setForeground(new java.awt.Color(0, 153, 255));
        listUser.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Aucun user" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(listUser);

        Recption.setBackground(new java.awt.Color(247, 247, 250));
        Recption.setColumns(20);
        Recption.setRows(5);
        Recption.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Message reçu", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Lucida Calligraphy", 0, 13))); // NOI18N
        Recption.setCaretColor(new java.awt.Color(0, 102, 255));
        jScrollPane2.setViewportView(Recption);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1)))
                .addContainerGap())
        );

        jPanel3.setBackground(new java.awt.Color(58, 107, 139));

        txtenvoi.setBackground(new java.awt.Color(225, 244, 255));
        txtenvoi.setColumns(20);
        txtenvoi.setRows(5);
        txtenvoi.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "saisir Text", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Lucida Calligraphy", 0, 14))); // NOI18N
        txtenvoi.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                EnterPressed(evt);
            }
        });
        jScrollPane3.setViewportView(txtenvoi);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(11, Short.MAX_VALUE)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        txtPan.setBackground(new java.awt.Color(58, 107, 139));
        txtPan.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Transfère de fichier", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Lucida Calligraphy", 1, 13))); // NOI18N

        BFile.setIcon(new javax.swing.ImageIcon(getClass().getResource("/chatGUI/Open16.gif"))); // NOI18N
        BFile.setText("File");
        BFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BFileActionPerformed(evt);
            }
        });

        yesBt.setText("Yes");
        yesBt.setEnabled(false);
        yesBt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                yesBtActionPerformed(evt);
            }
        });

        NoBt.setText("No");
        NoBt.setEnabled(false);
        NoBt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NoBtActionPerformed(evt);
            }
        });

        prgbar.setBackground(new java.awt.Color(51, 153, 255));
        prgbar.setForeground(new java.awt.Color(255, 255, 255));
        prgbar.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        pourcent.setText("%");

        javax.swing.GroupLayout txtPanLayout = new javax.swing.GroupLayout(txtPan);
        txtPan.setLayout(txtPanLayout);
        txtPanLayout.setHorizontalGroup(
            txtPanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(txtPanLayout.createSequentialGroup()
                .addGroup(txtPanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(txtPanLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(txtPanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(txtPanLayout.createSequentialGroup()
                                .addComponent(prgbar, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(pourcent, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(txtPanLayout.createSequentialGroup()
                                .addComponent(yesBt, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(23, 23, 23)
                                .addComponent(NoBt, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(txtPanLayout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addComponent(BFile, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        txtPanLayout.setVerticalGroup(
            txtPanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(txtPanLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(BFile)
                .addGap(18, 18, 18)
                .addGroup(txtPanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(yesBt)
                    .addComponent(NoBt))
                .addGap(18, 18, Short.MAX_VALUE)
                .addGroup(txtPanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(prgbar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pourcent, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(txtPan, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtPan, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BradioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BradioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_BradioActionPerformed

    private void deconnexionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deconnexionActionPerformed
        
        try {
            this.setVisible(false);
            cont.performDisconnect();
            conxFrame.setVisible(true); 
        } catch (UnknownHostException ex) {
            Logger.getLogger(ChatGui.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_deconnexionActionPerformed
          //appelé quand on appuis sur "ENTRÉE" pour envoyer un text
    private void EnterPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_EnterPressed
                   if(evt.getKeyChar() == Event.ENTER){
                       if(!listUser.isSelectionEmpty()){
                             System.out.println("txt: "+txtenvoi.getText());
                             cont.perfomSendMessage(txtenvoi.getText(), listUser.getSelectedValuesList());
                             txtenvoi.setText("");
                       }else javax.swing.JOptionPane.showMessageDialog(null,"Veuiller entrer un utilisateur SVP");
                   }
    }//GEN-LAST:event_EnterPressed

    private void BFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BFileActionPerformed
        int returnVal;
        if(!listUser.isSelectionEmpty()){
            returnVal = fc.showOpenDialog(this);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File file = fc.getSelectedFile();
                    //This is where a real application would open the file.
                    getRecption().append("On va envoyer: " + file.getName() + "." + "\n");
                    System.out.println("On envoi une demande de transfert de fichier "+ file.getName());
                    cont.perfomSendFileDemand(file,file.getName(), file.length(),listUser.getSelectedValuesList());
                } else {
                    getRecption().append("vous avez annullez l'envoi" + "\n");
                }
        }else javax.swing.JOptionPane.showMessageDialog(null,"Veuiller selectionner un utiisateur SVP");   
        
    }//GEN-LAST:event_BFileActionPerformed

    private void yesBtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yesBtActionPerformed
        if(!listUser.isSelectionEmpty()){
            try {
                cont.performTransfertConfirmation(listUser.getSelectedValuesList());
            } catch (IOException ex) {
                Logger.getLogger(ChatGui.class.getName()).log(Level.SEVERE, null, ex);
            }
        }else javax.swing.JOptionPane.showMessageDialog(null,"Veuiller selectionner un utilisateur SVP");
    }//GEN-LAST:event_yesBtActionPerformed

    private void NoBtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NoBtActionPerformed
         if(!listUser.isSelectionEmpty()){
             cont.performTransfertCancel(listUser.getSelectedValuesList());
        }else javax.swing.JOptionPane.showMessageDialog(null,"Veuiller selectionner un utilisateur SVP");
    }//GEN-LAST:event_NoBtActionPerformed

    private void conxxlogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_conxxlogActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_conxxlogActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            loginLabel.setText(conxxlog.getText());
            Bradio.setSelected(true);
            conxFrame.setVisible(false);
            this.setVisible(true);
            cont.setLocalUsername(conxxlog.getText());
            cont.setLocalUsername1(conxxlog.getText());
            cont.performConnect();
        } catch (UnknownHostException ex) {
            Logger.getLogger(ChatGui.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

   

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BFile;
    private javax.swing.JRadioButton Bradio;
    private javax.swing.JButton NoBt;
    private javax.swing.JTextArea Recption;
    private javax.swing.JLabel UserLab;
    private javax.swing.JFrame conxFrame;
    private javax.swing.JTextField conxxlog;
    private javax.swing.JButton deconnexion;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JList listUser;
    private javax.swing.JLabel log;
    private javax.swing.JLabel loginLabel;
    private javax.swing.JLabel pourcent;
    private javax.swing.JProgressBar prgbar;
    private javax.swing.JPanel txtPan;
    private javax.swing.JTextArea txtenvoi;
    private javax.swing.JButton yesBt;
    // End of variables declaration//GEN-END:variables

    /**
     * @param list
     */
    //On ajoute à la JList les éléments de la userList
    public void setListUser(ArrayList list) {
         DefaultListModel model = new DefaultListModel();
         for (int i = 0; i < list.size(); i++) {
            model.addElement(list.get(i)); 
        }
        this.listUser.setModel(model);   
    }

    /**
     * Permet d'écrire le message reçu à l'utilisateur
     * @param Recption the Recption to set
     */
    public void setRecption(String Recption) {
        this.getRecption().append(Recption);
        this.getRecption().setForeground(Color.blue);
    }

  

    /**
     * Permet de masquer ou affichier les boutons de contrôle pour le transfert de fichier.
     * @param state
     */
    public void setNoBt(boolean state) {
       this.NoBt.setEnabled(state);
        
    }

    /**
     * @param state
     */
    public void setYesBt(boolean state) {
        this.yesBt.setEnabled(state);
    }

    /**
     * @return the Recption
     */
    public javax.swing.JTextArea getRecption() {
        return Recption;
    }

    /**
     * @return the txtPan
     */
    public javax.swing.JPanel getTxtPan() {
        return txtPan;
    }

    /**
     * @param n
     */
    public void setPrgbar(int n) {
        this.prgbar.setValue(n);
    }

    /**
     * Permert de lister les thèmes disponibles sur une machine pour pouvoir choisir son thème préferer
     * @return
     */
    public Map<String,String> getLookAndFeelsMap(){
		UIManager.LookAndFeelInfo[] info = UIManager.getInstalledLookAndFeels();
		Map<String,String> map = new TreeMap<String,String>();
		for(int i=0; i<info.length;i++){
			String nomLF = info[i].getName();
			String nomClasse = info[i].getClassName();
			map.put(nomLF,nomClasse); 	
		}
		return map;	
	}

    /**
     * Creation du menu pour le style de page.
     */
    protected void createJMenuBar(){
		JMenuBar bar = new JMenuBar();
		JMenu menu = new JMenu("Style de page");
		ButtonGroup bg = new ButtonGroup();
		Map<String,String> map = getLookAndFeelsMap();
		for(String clef : map.keySet()){
			final String classe = map.get(clef);
			boolean natif = classe.equals(UIManager.getSystemLookAndFeelClassName());
			JRadioButtonMenuItem item = new JRadioButtonMenuItem(clef,natif);
			item.addActionListener(new ActionListener(){ 
				public void actionPerformed(ActionEvent ae){ 
					try{ 
						UIManager.setLookAndFeel(classe); 
					}catch(Exception e){
						e.printStackTrace();	
					} 
					SwingUtilities.updateComponentTreeUI(ChatGui.this); 
				} 
			}); 
			bg.add(item); 
			menu.add(item);  	
		}
		bar.add(menu);
		setJMenuBar(bar);
	}

    /**
     * Permet de donner la progression pour le transfert de fichier.
     * @param n
     */
    public void setPourcent(String n) {
        this.pourcent.setText(n);
    }
    
}
